<?php
namespace BoxSns\Widget;
class IndexWidget extends \WidgetController {

	/*******轮播图片****/
	function swiper($swiper_id) {
		$this->swiper_id = $swiper_id;
		$this->swiperData = BoxModel("addon_blocks_image")->get("status=1 and blocks_name='$swiper_id'");
		$this->display();
	}

	//小组列表
	function groupLists($param) {
		$type = $param['type'];
		//dump(array('is_show' => 1, 'type' => $type));

		$where = array('is_show' => 1, 'type' => $type);
		$list = BoxModel("sns_group")->get($where, "", "orderBy");
		foreach ($list as $k => $one) {
			if ($this->user_id) {
				$group_user = BoxModel("sns_group_user")->where(array('group_id' => $one['id'], 'user_id' => $this->user_id))->find();
			}
			if ($group_user) {
				$list[$k]['join'] = 1;
			} else {
				$list[$k]['join'] = 0;
			}
		}
		$this->list = $list;
		//dump(BoxModel("sns_group"));
		$this->display();

	}
	//小组列表
	function groupTopicList($param) {
		$type = $param['type'];
		$where = "type='$type' and is_show=1";
		$this->group_id = $group_id = $param['group_id'];
		$this->cate_id = $param['cate_id'];
		if (intval($group_id)) {
			$where .= " and pid='$group_id'";
		}
		if (intval($this->cate_id)) {
			$where .= " and cate_id='$this->cate_id'";
		}
		$data = BoxModel("sns_topic")->get($where, 10, "is_top desc, lastupdate desc");
		$this->list = $data['list'];
		$this->show_page($data['pager']);
		$this->display();
	}

	//小组头
	function groupInfo($param) {
		$id = $param['id'];
		$this->data = BoxModel("sns_group")->where(array('id' => $id))->find();
		if ($this->user_id) {
			$this->group_user = BoxModel("sns_group_user")->where(array('group_id' => $id, 'user_id' => $this->user_id))->find();
		}
		$this->display();
	}
	//小组用户
	function groupUser($param) {
		$this->group_id = $param['where']['group_id'];
		$data = BoxModel("sns_group_user")->get($param['where'], $param['limit'] ? $param['limit'] : 10, $param['orderBy']);
		foreach ($data['list'] as $k => $one) {
			$user = BoxModel("system_member")->load($one['user_id']);
			$data['list'][$k]['user'] = $user;
		}
		$this->list = $data['list'];
		$this->show_page($data['pager']);
		$this->display();
	}
/******用户等级***/
	public function user_tag($user_id) {
		return "正式会员";
	}
}